package com.nowcoder.community.util;/**
 * @description:
 * @Author HP
 * @create 2021/12/14 20:57
 */

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * @author HP
 * @create 2021-12-14 20:57
 * @desc 线程隔离工具类:持有用户信息，用于代替session对象
 **/
@Component
public class HostHolder {
    private ThreadLocal<User>users=new ThreadLocal<>();

    public User getUser(){
        return users.get();
    }

    public void setUser(User user){
        users.set(user);
    }

    public void clear(){
        users.remove();
    }

}
